<#import '/ftlLibrary/properteisVariable.ftl' as pv/>
<div class="row">
	<div class="col-lg-12 col-sm-12 col-xs-12">
		<div class="widget">
			<div class="widget-header bordered-bottom theme">
				<span class="widget-caption">活动-${(editModel=='add')?string('新增','编辑')}</span>
				<div class="widget-buttons">
					<a href="#" data-toggle="collapse">
						<i class="fa fa-minus"></i>
					</a>
					<a href="#" data-toggle="maximize">
						<i class="fa fa-expand"></i>
					</a>
				</div>
			</div>
			<div class="widget-body">
				<div class="row">
					<form class="editForm" action="${saveUrl}" method="post" responseType="JSON" role="form" id="editForm_${serializeNum}"
						data-bv-submitButtons="#editFormSubmitBtn_${serializeNum}"
						data-bv-message="This value is not valid"
						data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
						data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
						data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
							<input type="hidden" name="id" value="${editEntity.id}">
							<#if (true && editModel=='add')||(true && editModel=='edit')>
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<div class="form-group">
									<label for="name" class="col-sm-2 control-label no-padding-right">活动名称</label>
									<div class="col-sm-10">
										<input data-bv-message="The field is not valid" size="100" name="name" alt="活动名称" id="name" placeholder="活动名称" type="text" title="活动名称" class="form-control"  value="${editEntity.name}" />
										<span class="text"></span>
									</div>
								</div>
							</div>
							</#if>
							<#if (true && editModel=='add')||(true && editModel=='edit')>
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<div class="form-group">
									<label class="col-sm-2 control-label no-padding-right">推送位置</label>
									<div class="col-sm-6 control-label text-align-left checkboxStyle">
										<input type="hidden" name="pushPlace">
										<div class="col-xs-10  nomargin-bottom " style="padding-left: 2px!important;line-height: 28px">
											<@dictionary groupCode="pushPlace";dics>
											<#list dics as dic>
											<label>
												<input type="checkbox" name="pushPlaceChk"  class="chk" value="${dic.code}" style="margin-right: 5px;opacity: 1;position: static;height: 18px!important;margin-top: 4px!important;" >
											</label>
											<label style="margin-right: 10px" >${dic.value}</label>
											</#list>
											</@dictionary>
										</div>
									</div>
								</div>
							</div>
							</#if>
							<#if (true && editModel=='add')||(true && editModel=='edit')>
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<div class="form-group">
									<label class="col-sm-2 control-label no-padding-right">参与对象</label>
									<div class="col-sm-10">
										<input data-bv-message="The field is not valid" size="715827882" name="participationObjecct" alt="参与对象" id="participationObjecct" placeholder="家长，2-3岁宝宝，3-4岁宝宝" type="text" title="参与对象" class="form-control"  value="${editEntity.participationObjecct}" />
										<span class="text"></span>
									</div>
								</div>
							</div>
							</#if>
							<#if (true && editModel=='add')||(true && editModel=='edit')>
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<input type="hidden" name="publicityImage" value="${editEntity.publicityImage}">
								<input type="hidden" name="deletePublicityImage">
								<div class="form-group">
									<label class="col-sm-2 control-label no-padding-right">活动宣传图</label>
									<div class="col-sm-10">
										<div class="col-xs-9">
											<input data-bv-message="The field is not valid" maxlength="100" name="newPublicityImage"
												   id="publicityImage${serializeNum}" readonly="readonly" alt="活动宣传图" placeholder="活动宣传图"
												   type="text" title="活动宣传图" class="form-control"/>
											<span class="text"></span>
										</div>
										<div class="col-sm-2">
											<a href="javascript:void(0);" class="btn theme"
											   onclick="uploadPublicityImage('editForm_${serializeNum}','newPublicityImage','publicityImage','publicityImage_imgPrev${serializeNum}','publicityImage')"><i
													class="fa fa-upload"></i>上传</a>
										</div>
										<div class="col-sm-12 imgPrev" id="publicityImage_imgPrev${serializeNum}">
											<@config key="qiniu.domain" inner="true";qiniuDomin>
											<@file fileIds=editEntity.publicityImage separator=',';files>
											<#list files as file>
											<p>
												<!--<img src="${pv.fileRedPath}/${file.relativePath}/${file.fileName}" width="50" height="50">-->
												<img src="http://${qiniuDomin}/${file.qiniuKey}" width="50" height="50"
													 class="imgViewer">
												${file.fileName}
												<#if file.size??>&nbsp;&nbsp;尺寸:${file.size}</#if>
											<a class="btn btn-default btn-xs icon-only red delete textAling-right"
											   href="javascript:void(0);"
											   onclick="removeFileUseLog(this,'editForm_${serializeNum}','deletePublicityImage','publicityImage','${file.id}')"><i
													class="fa fa-trash-o"></i></a>
											</p>
											</#list>
											</@file>
											</@config>
										</div>
									</div>
								</div>
							</div>
							</#if>
							<#if (true && editModel=='add')||(true && editModel=='edit')>
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<div class="form-group">
									<label style="width: 95px;text-align: center"><span style="color: red">*</span>活动日期：</label>
									<label>
										<input id="d4313" type="text" class="beginValue Wdate" placeholder="请选择" name="activityBeginDate"
											   onFocus="WdatePicker({doubleCalendar:true,maxDate:'#F{$dp.$D(\'d4314\')}',dateFmt:'yyyy-MM-dd'})" style="width: 70px;vertical-align: middle;height: 30px!important;padding-left:3px!important;border: 1px solid #c6d5d8;border-radius: 4px !important;">
										至
										<input id="d4314" type="text" class="endValue Wdate" placeholder="请选择" name="activityEndDate"
											   onFocus="WdatePicker({doubleCalendar:true,minDate:'#F{$dp.$D(\'d4313\')}',dateFmt:'yyyy-MM-dd'})" style="width: 70px;vertical-align: middle;height: 30px!important;padding-left:3px!important;border: 1px solid #c6d5d8;border-radius: 4px !important;">
									</label>
								</div>
							</div>
							</#if>
							<#if (true && editModel=='add')||(true && editModel=='edit')>
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<div class="form-group has-feedback">
									<label class="col-sm-2 control-label no-padding-right">是否报名</label>
									<div class="col-sm-6 control-label text-align-left checkboxStyle">
										<label>
											<input  type="radio" name="isApply"
													style="margin-right: 5px;opacity: 1;position: static;height: 18px!important;" value="0">
										</label>
										<label style="margin-right: 10px">需要</label>
										<label >
											<input type="radio" name="isApply"
												   style="margin-right: 5px;opacity: 1;position: static;height: 18px!important;" value="1">
										</label>
										<label style="margin-right: 10px">不需要</label>
									</div>
								</div>
							</div>
							</#if>
							<#if (true && editModel=='add')||(true && editModel=='edit')>
							<div class="col-xm-12 col-sm-6 col-lg-4">
								<div class="form-group">
									<label class="col-sm-2 control-label no-padding-right">活动区域</label>
									<div>
										<label class="col-xs-10 col-md-10 col-lg-10 nomargin-bottom " style="padding-left: 2px!important;">
											<label class="nomargin-bottom">
												<select name="addressProvince" class="addressProvince col-xs-12 col-md-12 col-lg-12 nopadding">
													<option value="">请选择</option>
													<@dictionary groupCode="addressProvince";dics>
													<#list dics as dic>
													<option value="${dic.code}">${dic.value}</option>
												</#list>
											</@dictionary>
											</select>
										</label>
										<label>
											省
										</label>
										<label class="nomargin-bottom">
											<select name="addressCity" class="addressCity col-xs-12 col-md-12 col-lg-12 nopadding">
												<option  value="">请选择</option>
											</select>
										</label>
										<label>
											市
										</label>
										<label class="nomargin-bottom">
											<select name="addressRegion" class="addressRegion col-xs-12 col-md-12 col-lg-12 nopadding">
												<option  value="">请选择</option>
											</select>
										</label>
										<label>
											区
										</label>
										<label class="nomargin-bottom">
											<input data-bv-message="The field is not valid" style="max-width: 200px"
												   name="address" onkeyup="inputValueLength(this,50)"
												   alt="家庭住址" id="address" placeholder="活动详细地址" type="text"
												   title="家庭住址"
												   class="form-control" value="${editEntity.address}"/>
										</label>
									</div>
								</div>
							</div>
							</#if>
							<#if (true && editModel=='add')||(true && editModel=='edit')>
								<div class="form-group">
									<label for="activityDetails" class="col-sm-2 control-label">活动详情：</label>
									<div class="col-sm-8">
										<script id="activityDetails" name="activityDetails" type="text/plain"></script>
										<script type="text/javascript" src="assets/js/editors/ueditor1_4_3_utf8-jsp/utf8-jsp/ueditor.config.js"></script>
										<script type="text/javascript" src="assets/js/editors/ueditor1_4_3_utf8-jsp/utf8-jsp/editor_api.js"></script>
										<script type="text/javascript" src="assets/js/editors/ueditor1_4_3_utf8-jsp/utf8-jsp/ueditor.all.js"></script>
										<script type="text/javascript" src="assets/js/editors/ueditor1_4_3_utf8-jsp/utf8-jsp/third-party/zeroclipboard/ZeroClipboard.js"></script>
										<script type="text/javascript" charset="utf-8" src="assets/js/editors/ueditor1_4_3_utf8-jsp/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
										<script type="text/javascript">
											var ue = UE.getEditor('activityDetails');
											var lang = ue.getOpt('lang'); //默认返回：zh-cn
										</script>
									</div>
								</div>
							</#if>
						<div class="col-sm-12">
							<input type="button" class="btn btn-default" data-dismiss="modal" value="返回">
							<button type="submit" class="btn btn-blue" id="editFormSubmitBtn_${serializeNum}" onclick="beforeSubmit()">保存</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="assets/js/validation/bootstrapValidator_init.js"></script>
<script>
    initImgPrev($(".imgPrev"));
	/**
	*获取省份
    */
    $(function () {
        ajaxRequest("sysCitysController/provinceList.do", null, function (result) {
            var data = result.data;
            var arr = ['<option value="0">请选择</option>'];
            $.each(data, function (i, t) {
                arr.push('<option value="' + t.id + '">' + t.name + '</option>')
            })
            $(".addressProvince").html(arr.join(''))
        }, function () {
            logger.error("加载省失败!");
        }, "get", "json")
    });

    /**
     * 获取市
     */
    $(".addressProvince").change(function () {
        var nowSelectedProvince = $(this).val();
        ajaxRequest("sysCitysController/getChildrens.do", {
            pId: nowSelectedProvince
        }, function (result) {
            var data = result.data;
            var arr = ['<option value="0">请选择</option>'];
            $.each(data, function (i, t) {
                arr.push('<option value="' + t.id + '">' + t.name + '</option>')
            })
            $(".addressCity").html(arr.join(''))

        }, function () {
            logger.error("加载城市失败!");
        }, "get", "json")
    });


    /**
     * 获取区
     */
    $(".addressCity").change(function () {
        var nowSelectedProvince = $(this).val();
        ajaxRequest("sysCitysController/getChildrens.do", {
            pId: nowSelectedProvince
        }, function (result) {
            var data = result.data;
            var arr = ['<option value="0">请选择</option>'];
            $.each(data, function (i, t) {
                arr.push('<option value="' + t.id + '">' + t.name + '</option>')
            })
            $(".addressRegion").html(arr.join(''))

        }, function () {
            logger.error("加载城区失败!");
        }, "get", "json")
    });
	$(".selectpicker_${serializeNum}").select2();

    /**
	 * 提交之前拼接推送位置数据
     */
	function beforeSubmit() {
        //获取推送位置数据
        var pushPlace = new Array();
        $("[name='pushPlaceChk']:checked").map(function (index, chk) {
            var value = chk.value;
            pushPlace.push(value);
        });
        var pushPlaceStr = pushPlace.join(",");
		$("[name='pushPlace']").val(pushPlaceStr);
    }
</script>
<script type="text/javascript">
    function uploadPublicityImage(formId, targetShowInputName, targetHideInputName, imgPrevId, groupName) {
        showUploadFileDialog({
            groupName: groupName,//该参数将参与文件缓存时的唯一标识值,如果配置了文件服务器,该参数同时会参与文件服务器文件存储目录分配,为保证文件不丢失, 务必保证同一编辑页面此参数唯一
            size: "large",//文件上传组件层大小，small 小,large 大
            title: "文件上传",//文件上传组件层标题
            width: "",//文件上传组件层宽度
            height: "",//文件上传组件层高度
            fileNumLimit: 1,//验证文件总数量, 超出则不允许加入队列
            fileSizeLimit: "209715200",// 验证文件总大小是否超出限制, 超出则不允许加入队列
            fileSingleSizeLimit: "52428800",
            accept: {
                title: "图片文件",//文字描述
                extensions: "gif,jpg,jpeg,bmp,png,psd",//允许的文件后缀，不带点，多个用逗号分割
                mimeTypes: "image/jpg,image/jpeg,image/png,image/gif,image/bmp,image/psd"// 多个用逗号分割
            },
            imgMaxWidth: "-1",//图片文件允许的最大宽度
            imgMaxHeight: "-1",// 图片文件允许的最大高度
            sizes: '',//缩放尺寸(格式：宽度-高度,宽度-高度,宽度-高度....),如：500-300,400-300
        }, function (result) {//点击确认的回调函数
            if (result) {
                console.log(result.fileList);
                var showWidth = 50, showHeight = 50;
                var fileList = result.fileList;
                $("#" + imgPrevId + " p a").click();
                for (var i = 0, len = fileList.length; i < len; i++) {
                    var file = fileList[i];
                    var width = file.size.width;
                    var height = file.size.height;
                    var uuid = file.uuid;
                    var targetInput = $("#" + formId + " [name='" + targetShowInputName + "']").val(groupName + "=>" + targetHideInputName);
                    if (width == -1 && height == -1) {
                        $("#" + imgPrevId).append('<p><img  class="imgViewer"  src="fileUpload/previewUploadImg.do?groupName=' + groupName + '&fileId=' + uuid + '" width="' + showWidth + '" height="' + showHeight + '">' + file.name + '<a class="btn btn-default btn-xs icon-only red delete" href="javascript:void(0);" onclick="removePublicityImageUploadTempleFile(this,' + "'" + groupName + "','" + uuid + "'" + ')"><i class="fa fa-trash-o"></i></a></p>');
                    }
                }
            }
        }, function () {//点击取消的回调函数
            console.log("执行关闭/取消的回调函数");
        })
    }

    //移除临时文件
    function removePublicityImageUploadTempleFile(that, groupName, uuid) {
        console.log("clear temp file  by  id...")
        ajaxRequest("fileUpload/clearTempFile.do", {groupName: groupName, fileId: uuid}, function (result) {
                if (result.resCode == "200") {
                    console.log("成功清除缓存文件：" + uuid);
                    $(that).parents("p").remove();
                } else {
                    var message = result.resMsg;
                    bootbox.alert({
                        title: "错误提示",
                        size: 'small',
                        message: message
                    });
                }
            },
            function (XMLHttpRequest, textStatus, errorThrown) {
                ajaxError(errorThrown);
            }, "GET", "JSON")
    }

    function removeFileUseLog(that, formId, targetDeleteInputName, targetHideInputName, fileId) {
        var useFileIds = $("#" + formId + " [name='" + targetHideInputName + "']");
        var targetDeleteInput = $("#" + formId + " [name='" + targetDeleteInputName + "']");
        var ids = useFileIds.val().split(",");
        var newIds = "";
        for (var i = 0, len = ids.length; i < len; i++) {
            if (ids[i] == fileId) {
                targetDeleteInput.val(targetDeleteInput.val() + "," + fileId);
                continue;
            }
            newIds += ids[i];
            if (i != len - 1) {
                newIds += ",";
            }
        }
        useFileIds.val(newIds);
        $(that).parents("p").remove();
    }
</script>